package com.cloud.client.service;

import com.cloud.client.service.fallback.FileFallback;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @packageName: com.cloud.client.service
 * @name: FileService
 * @description: 文件相关服务
 * @author: 董定卓
 * @dateTime: 2019/7/15 15:50
 */
@FeignClient(name = "service-gateway-file", url = "${gateway.url}", path = "/service-file", fallback = FileFallback.class, configuration = FileService.FileConfig.class)
public interface FileService {

    /**
     * 文件上传
     *
     * @param map
     * @param file
     * @return
     */
    @PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Object fileUpload(@RequestParam Map<String, Object> map, @RequestPart("file") MultipartFile file);

    /**
     * 文件分页列表
     *
     * @param map
     * @return
     */
    @PostMapping("/file/page")
    Object filePage(@RequestParam Map<String, Object> map);


    class FileConfig {
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }
}
